﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace calendar_generator
{
	/// <summary>
	/// Represents Chinese months during one solar western year
	/// </summary>
	class MilestonesData
	{
		/// <summary>
		/// Milestones - Dates that mark Starts of all 24 seasons
		/// </summary>
		private List<DateTime> milestones;

		public List<DateTime> Milestones { get { return milestones; } }

		/// <summary>
		/// Get the list of start dates of moths or half moths
		/// </summary>
		/// <param name="reminder">Zero big moths; One - half month
		/// </param>
		/// <returns></returns>
		public List<DateTime> GetMonthDates(int reminder)
		{
			List<DateTime> ret = new List<DateTime>();

			for (int i = 0; i < milestones.Count; i++)
			{
				if (i % 2 == reminder)
				{ ret.Add(milestones[i]); }
			}

			return ret;
		}

		public MilestonesData(int year)
		{
			switch (year)
			{
				case 2010:
					milestones = new List<DateTime>()
					{	
						// From previous Chinese year
						new DateTime(year - 1, 12, 7), new DateTime(year - 1, 12, 22),	// From the previous western year
						new DateTime(year, 1, 5), new DateTime(year, 1, 20),
						// Here the Chinese and western year are the same
						new DateTime(year, 2, 4), new DateTime(year, 2, 19), new DateTime(year, 3, 6),
						new DateTime(year, 3, 21), new DateTime(year, 4, 5), new DateTime(year, 4, 20),
						new DateTime(year, 5, 5), new DateTime(year, 5, 21), new DateTime(year, 6, 6),
						new DateTime(year, 6, 21), new DateTime(year, 7, 7), new DateTime(year, 7, 23),
						new DateTime(year, 8, 7), new DateTime(year, 8, 23), new DateTime(year, 9, 8),
						new DateTime(year, 9, 23), new DateTime(year, 10, 8), new DateTime(year, 10, 23),
						new DateTime(year, 11, 7), new DateTime(year, 11, 22), new DateTime(year, 12, 7),
						new DateTime(year, 12, 22)		// The beginning oh the last Chinese month
					};
					break;

				case 2011:
					milestones = new List<DateTime>()
					{
						new DateTime(year - 1, 12, 7), new DateTime(year - 1, 12, 22),	// From the previous western year
						new DateTime(year, 1, 6), new DateTime(year, 1, 20),
						new DateTime(year, 2, 4), new DateTime(year, 2, 19), new DateTime(year, 3, 6),
						new DateTime(year, 3, 21), new DateTime(year, 4, 5), new DateTime(year, 4, 20),
						new DateTime(year, 5, 6), new DateTime(year, 5, 21), new DateTime(year, 6, 6),
						new DateTime(year, 6, 22), new DateTime(year, 7, 7), new DateTime(year, 7, 23),
						new DateTime(year, 8, 8), new DateTime(year, 8, 23), new DateTime(year, 9, 8),
						new DateTime(year, 9, 23), new DateTime(year, 10, 8), new DateTime(year, 10, 24),
						new DateTime(year, 11, 8), new DateTime(year, 11, 22), new DateTime(year, 12, 7),
						new DateTime(year - 1, 12, 22)
					};
					break;

				case 2012:
					milestones = new List<DateTime>()
					{
						new DateTime(year - 1, 12, 7), new DateTime(year - 1, 12, 22),	// From the previous western year
						new DateTime(year, 1, 6), new DateTime(year, 1, 20),			// Emo's - changed from 05.Jan
						new DateTime(year, 2, 4), new DateTime(year, 2, 19), new DateTime(year, 3, 5),
						new DateTime(year, 3, 20), new DateTime(year, 4, 4), new DateTime(year, 4, 19),
						new DateTime(year, 5, 5), new DateTime(year, 5, 20), new DateTime(year, 6, 5),
						new DateTime(year, 6, 21), new DateTime(year, 7, 6), new DateTime(year, 7, 22),
						new DateTime(year, 8, 7), new DateTime(year, 8, 22), new DateTime(year, 9, 7),
						new DateTime(year, 9, 22), new DateTime(year, 10, 8), new DateTime(year, 10, 23),
						new DateTime(year, 11, 7), new DateTime(year, 11, 22), new DateTime(year, 12, 7),
						new DateTime(year, 12, 21)
					};
					break;

				case 2013:
					milestones = new List<DateTime>()
					{
						new DateTime(year - 1, 12, 7), new DateTime(year - 1, 12, 21),	// From the previous western year
						new DateTime(year, 1, 5), new DateTime(year, 1, 20),
						new DateTime(year, 2, 3), new DateTime(year, 2, 18), new DateTime(year, 3, 5),
						new DateTime(year, 3, 20), new DateTime(year, 4, 4), new DateTime(year, 4, 20),
						new DateTime(year, 5, 5), new DateTime(year, 5, 21), new DateTime(year, 6, 5),
						new DateTime(year, 6, 21), new DateTime(year, 7, 7), new DateTime(year, 7, 22),		// Emo's - changed from 08.July
						new DateTime(year, 8, 7), new DateTime(year, 8, 23), new DateTime(year, 9, 7),
						new DateTime(year, 9, 23), new DateTime(year, 10, 8), new DateTime(year, 10, 23),	// Emo's - changed from 22.Sep
						new DateTime(year, 11, 7), new DateTime(year, 11, 22), new DateTime(year, 12, 7),
						new DateTime(year, 12, 22)
					};
					break;

				case 2014:
					milestones = new List<DateTime>()
					{
						// 2013-12-10 - Correct dates for 2014 entered
						new DateTime(year - 1, 12, 7), new DateTime(year - 1, 12, 22),
						new DateTime(year, 1, 5), new DateTime(year, 1, 20),
						new DateTime(year, 2, 4), new DateTime(year, 2, 18), new DateTime(year, 3, 5),
						new DateTime(year, 3, 20), new DateTime(year, 4, 4), new DateTime(year, 4, 20),
						new DateTime(year, 5, 5), new DateTime(year, 5, 21), new DateTime(year, 6, 5),
						new DateTime(year, 6, 21), new DateTime(year, 7, 7), new DateTime(year, 7, 22),
						new DateTime(year, 8, 7), new DateTime(year, 8, 23), new DateTime(year, 9, 7),
						new DateTime(year, 9, 23), new DateTime(year, 10, 8), new DateTime(year, 10, 23),
						new DateTime(year, 11, 7), new DateTime(year, 11, 22), new DateTime(year, 12, 7),
						new DateTime(year, 12, 22)
					};
					break;

				// 2015-01-13 - Correct dates for 2015 entered
				case 2015:
					/*
					 * Year2014	
					... "2014-12-07T05:05","20214-12-21T23:04","2015-01-05T16:21","2015-01-20T09:44"]
					
					 * Year2015	
					["2015-02-04T03:59","2015-02-19T00:00","2015-03-05T21:56","2015-03-20T22:46",

					-- BEGIN UT+03 (29.03)
					"2015-04-05T02:40","2015-04-20T09:42","2015-05-05T19:53","2015-05-21T08:45",
					"2015-06-05T23:59","2015-06-21T16:38","2015-07-07T10:13","2015-07-23T03:31",
					"2015-08-07T20:02","2015-08-23T10:38","2015-09-07T23:00","2015-09-23T08:21",
					"2015-10-08T14:43","2015-10-23T17:47",
					-- END UT+03 (25.10)

					"2015-11-07T17:59","2015-11-22T15:26","2015-12-07T10:54","2015-12-22T04:48",
					"2016-01-05T22:09","2016-01-20T15:28"]
					*/

					//2015-01-17 - Emo's fixes
					// New: 06.01, 06.03, 22.06, 08.08, 09.10, 24.10, 08.11, 23.11
					milestones = new List<DateTime>()
					{
						new DateTime(year - 1, 12, 7), new DateTime(year - 1, 12, 22),
						new DateTime(year, 1, 6), new DateTime(year, 1, 20),new DateTime(year, 2, 4), new DateTime(year, 2, 19), 
						new DateTime(year, 3, 6), new DateTime(year, 3, 22), new DateTime(year, 4, 5), new DateTime(year, 4, 20),
						new DateTime(year, 5, 5), new DateTime(year, 5, 21), new DateTime(year, 6, 6), new DateTime(year, 6, 21),
						new DateTime(year, 7, 7), new DateTime(year, 7, 23), new DateTime(year, 8, 8), new DateTime(year, 8, 23),
						new DateTime(year, 9, 8), new DateTime(year, 9, 23), new DateTime(year, 10, 9), new DateTime(year, 10, 24),
						new DateTime(year, 11, 8), new DateTime(year, 11, 23), new DateTime(year, 12, 7), new DateTime(year, 12, 22)
					};
					break;

				default:
					//Load default milestones
					// 2013-12-10 - First day of the year set to 4th of February - it is more often
					milestones = new List<DateTime>()
					{
						// 2013-10-30 - Some start dates fixed (subtract one day)
						new DateTime(year, 2, 4), new DateTime(year, 2, 19), new DateTime(year, 3, 6),
						new DateTime(year, 3, 21), new DateTime(year, 4, 5), new DateTime(year, 4, 21),
						new DateTime(year, 5, 6), new DateTime(year, 5, 22), new DateTime(year, 6, 6),
						new DateTime(year, 6, 22), new DateTime(year, 7, 7), new DateTime(year, 7, 23),
						new DateTime(year, 8, 8), new DateTime(year, 8, 24), new DateTime(year, 9, 8),
						new DateTime(year, 9, 23), new DateTime(year, 10, 9), new DateTime(year, 10, 24),
						new DateTime(year, 11, 8), new DateTime(year, 11, 23), new DateTime(year, 12, 8),
						new DateTime(year, 12, 22), new DateTime(year, 1, 6), new DateTime(year, 1, 21)
					};
					break;
			}
		}
	}
}
